<?php
/**
 * 页面的地址接口
 * @author:wangjingming
 * @date：2017 11 17
 */
use Think\Controller;

class BaseController extends Controller {

    protected $_user = array();

    protected function _initialize()
    {
        $access_token = getParam('access_token', "");
        if ($access_token != "") {

            $cur_user_id = D('UserToken')->getUserIdByAccessToken($access_token);
            if ($cur_user_id > 0) {
                $this->_user = D('User')->getSelfInfo($cur_user_id);
            }
        }

        $action = strtolower(ACTION_NAME);
        if ($this->_user == false && $action != 'index' && $action != 'login') {
            redirect("/index.php?m=home&c=Index&a=index");
        }
       // dump($this->_user);
        /*if ($this->_user != false) {
            $action_array = array(
                'admin' => 5,
                'police' => 4,
                'collector' => 3,
                'checker' => 2,
                'centerperson' => 1
            );
            $url_array = array(
                '5' => 'admin',
                '4' => 'police',
                '3' => 'collector',
                '2' => 'checker',
                '1' => 'centerPerson'
            );

            if (isset($action_array[$action])) {
                $type = $action_array[$action];
                if ($type != $this->_user['type']) {
                    redirect("/index.php?m=home&c=index&a={$url_array[$this->_user['type']]}");
                }
            }
        }*/
    }
}
